﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace System.Net.Http.Headers
{
    /// <summary>
    /// HttpHeadersExtension
    /// </summary>
    public static partial class HttpHeadersExtension
    { 
        /// <summary>
        /// 获取给定的Key的 HttpHeaderValue
        /// </summary>
        /// <param name="headers"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetHeaderValue(this HttpHeaders headers, string key)
        {
            IEnumerable<string> values = null;
            return headers.TryGetValues(key, out values) ? values.FirstOrDefault() : string.Empty;
        }
    }
}
